package com.uphone.kingmall.adapter;

import android.view.View;
import android.widget.CheckBox;
import android.widget.CompoundButton;
import android.widget.ImageView;

import com.blankj.utilcode.util.SizeUtils;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.china.zhuoyue.R;
import com.uphone.kingmall.bean.UserCollectGoodsBean;
import com.uphone.kingmall.utils.GlideUtils;

/**
 * <pre>
 *     author : 王雨
 *     e-mail :
 *     time   : 2018/07/31
 *     desc   :
 *     version: 1.0
 * </pre>
 */
public class FavoriteAdapter extends BaseQuickAdapter<UserCollectGoodsBean.DataBean, BaseViewHolder> {
    private boolean manager = false;
    private OnShopItemClickListener listener;

    public FavoriteAdapter() {
        super(R.layout.kingmall_item_favorite);
    }

    @Override
    protected void convert(final BaseViewHolder helper, final UserCollectGoodsBean.DataBean item) {
        helper.setText(R.id.tv_title, item.getGoodsName() + "");
        helper.setText(R.id.tv_collect_num, "" + item.getCollectCount() + "人收藏");
        helper.setText(R.id.tv_price, "¥" + item.getGoodsPrice());
        ImageView iv = helper.getView(R.id.iv_icon);
        GlideUtils.getInstance().loadCornerImage(mContext, item.getGoodsMainImg(), SizeUtils.dp2px(2), iv);
        final CheckBox iv_select = helper.getView(R.id.iv_select);
        iv_select.setChecked(item.isSelect());
        if (manager) {
            iv_select.setVisibility(View.VISIBLE);
        } else {
            iv_select.setVisibility(View.GONE);
        }
        iv_select.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
                item.setSelect(isChecked);
                if (listener != null) {
                    listener.itemSelect(iv_select, helper.getLayoutPosition(), item);
                }
            }
        });
    }

    public void setManager(boolean manager) {
        this.manager = manager;
        notifyDataSetChanged();
    }

    public void setOnShopItemClickListener(OnShopItemClickListener listener) {
        this.listener = listener;
    }

    public interface OnShopItemClickListener {

        void itemSelect(View v, int position, UserCollectGoodsBean.DataBean item);
    }
}
